# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=xz
pkgver=5.6.3
pkgrel=0
pkgdesc="Library and CLI tools for XZ and LZMA compressed files"
url="https://tukaani.org/xz/"
arch="all"
license="GPL-2.0-or-later AND 0BSD AND Public-Domain AND LGPL-2.1-or-later"
makedepends="autoconf automake libtool gettext-tiny"
depends_dev="$pkgname=$pkgver-r$pkgrel"
subpackages="$pkgname-static $pkgname-dev $pkgname-doc $pkgname-libs"
source="https://github.com/tukaani-project/xz/archive/refs/tags/v$pkgver/xz-$pkgver.tar.gz"

# secfixes:
#   5.2.5-r1:
#     - CVE-2022-1271
#   5.6.1-r2:
#     - CVE-2024-3094

prepare() {
	default_prepare
	autoreconf -fi
}

build() {
	# compression utility
	CFLAGS="$CFLAGS -O3" \
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--infodir=/usr/share/info \
		--localstatedir=/var \
		--disable-rpath \
		--disable-werror \
		--disable-doc

	sed -i \
		-e 's|^hardcode_libdir_flag_spec=.*|hardcode_libdir_flag_spec=""|g' \
		-e 's|^runpath_var=LD_RUN_PATH|runpath_var=DIE_RPATH_DIE|g' \
		libtool
	make
}

check() {
	LD_LIBRARY_PATH="$(pwd)/src/liblzma/.libs" make check || {
		cat tests/test-suite.log
		return 1
	}
}

package() {
	make DESTDIR="$pkgdir" install
}

sha512sums="
0f814f4282c87cb74a8383199c1e55ec1bf49519daaf07f7b376cb644770b75cc9257c809b661405fcfd6cda28c54d799c67eb9e169665c35b1b87529468085e  xz-5.6.3.tar.gz
"
